<?php
  mb_internal_encoding('utf-8');
  require "./karkkainen_sanders.php";

  function str2start(&$_str){
    $len = mb_strlen($_str);
    $array_str = $alphabet = array();
    for($i=0;$i<$len;++$i){
      $letter = mb_substr($_str,$i,1);
      $array_str[] = $letter;
      $alphabet[$letter] = true;
    }
    $alphabet[chr(1)] = true;
    $array_str[]=chr(1);
    $array_str[]=chr(1);
    $array_str[]=chr(1);
    $alphabet = array_keys($alphabet);
    sort($alphabet,SORT_STRING);
    return array($array_str,$alphabet);
  }


  $str = "自制燃烧弹，无奈家庭作坊做的燃烧弹只能用瓶子，技术上自然就遇到了瓶颈，威力太小，被消防车轻松扑灭以后，消防车的高压水枪对准潘女士扫射，最终潘女士缴械投降。";

  $str="L'affaire Clearstream est une vaste histoire de manipulation, dans laquelle des listings bancaires ont été falsifiés et transmis à un juge.";

  $str="Through their mothers, President Obama and Massachusetts Sen.-elect Scott Brown are descendants of a man who lived in the 1600s, genealogists say.";

  $str = "cbaé0abc"; 

  list($array_str,$alphabet) = str2start($str);
  $out = array_fill(0,count($array_str),chr(1));
  $n = count($array_str)-3;
  sortSuffixArray($array_str,$out,$n,$alphabet);

  for($i=0;$i<$n;++$i){
    $offset = $out[$i];
    $suffix = mb_substr($str,$offset,20);    
// uncomment the next line if you want to print the entire suffix  
//    $suffix = mb_substr($str,$offset,$n-$offset);
    echo $offset."::[".$suffix."]\n";
  }

?>
